package com.yc.snack.dao.impl;

import java.util.List;

import com.yc.snack.dao.IProductInfoDao;
import com.yc.snack.dao.util.DBUtil;
import com.yc.snack.entity.ProductInfo;

public class ProductInfoDaoImpl implements IProductInfoDao {

	@Override
	public int add(ProductInfo pf) {
		DBUtil db = new DBUtil();
		String sql = "insert into goodsinfo values(0,?,?,?,?,?,?,?,?,?,?,1)";
		return db.update(sql, pf.getGname(),pf.getTno(),pf.getPrice(),pf.getIntro(),pf.getBalance(),
				pf.getPics(),pf.getUnit(),pf.getQperied(),pf.getWeight(),pf.getDescr());
	}

	@Override
	public List<ProductInfo> finds(int page, int rows) {
		DBUtil db = new DBUtil();
		String sql = "select gno,gname,price,weight,pics from goodsInfo order by gno desc limit ?, ?";
		return db.find(ProductInfo.class, sql, (page - 1) * rows,rows);
	}

	@Override
	public int total() {
		DBUtil db = new DBUtil();	
		String sql = "select count(gno) from goodsInfo";
		return Integer.parseInt(db.findStr(sql));
	}

}
